<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用命名规则保护属性</title>
</head>
<body>
    <script>
        class Request{
            // 保护_url
            _url = 'https://ftgyfuyhg';
            constructor(name){
                this.name = name;
            }

            set url(url){
                if(!/^https?:\/\//i.test(url)){
                    throw new Error("地址格式错误！");
                }
                this._url = url;
            }
            get url(){
                return this._url;
            }
        }

        let request = new Request("hafsdjkasd");
        request.url = '5678796ftgyfuyhg';
        console.log(request.url);

        // 但是使用request._url还是能改变_url的值
    </script>
</body>
</html>